<template>
  <view class="ss-cube-wrap">
    <view class="dwonclass">
       <view class="downitem" v-for="(item,index) in data.list" :key="index"  @tap="getdown(item)">
         <view class="daoview" v-if="item.type == 'djs'">
          <image class="daoviewimg" :src="sheep.$url.cdn(item.image)" mode=""></image>
          <view class="daoitems">
            <view class="jishi">
              <view class="jiitem">
                <text class="daonum">倒计时：</text>
                <uni-countdown :show-day="false" :second="item.cha" color="#fff" splitorColor="#fff" />
              </view>
            </view>
            <text class="daomiaotit">{{ item.text }}</text>
            <view class="jishi">
              <text class="qiang">立即抢券</text>
            </view>
          </view>
         </view>
         <image class="cube-img" :src="sheep.$url.cdn(item.image)" mode="" v-else></image>
       </view>
       <!-- <view class="downitem">
        <image class="cube-img" src="https://pindongwang.oss-cn-beijing.aliyuncs.com/uploads/20240610/df0eaa722d49cab69b4a581e35abbc67.jpg" mode=""></image>
       </view> -->
    </view>
  </view>
  <!-- <view class="ss-cube-wrap" :style="[parseAdWrap]">
    <view v-for="(item, index) in data" :key="index">
      <view
        class="cube-img-wrap"
        :style="[parseImgStyle(item), { margin: '7rpx' }]"
        @tap="sheep.$router.go(item.url)"
      >
        <image class="cube-img" :src="sheep.$url.cdn(item.src)" mode="aspectFill"></image>
      </view>
    </view>
  </view> -->
</template>
<script setup>
  /**
/**
 * 广告魔方
 *
 * @property {Array<Object>} list 			- 魔方列表
 * @property {Object} styles 				- 组件样式
 * @property {String} background 			- 组件背景色
 * @property {Number} topSpace 				- 组件顶部间距
 * @property {Number} bottomSpace 			- 组件底部间距
 * @property {Number} leftSpace 			- 容器左间距
 * @property {Number} rightSpace 			- 容器右间距
 * @property {Number} imgSpace 				- 图片间距
 * @property {Number} imgTopRadius 			- 图片上圆角
 * @property {Number} imgBottomRadius 		- 图片下圆角
 *
 */

  import { computed, inject, unref } from 'vue';
  import sheep from '@/sheep';
  import { useDurationTime } from '@/sheep/hooks/useGoods';

  // 参数
  const props = defineProps({
    data: {
      type: Object,
      default() {},
    },
    styles: {
      type: Object,
      default() {},
    },
  });

  function dao(time){
    console.log(useDurationTime(time))
    return useDurationTime(time)
  }
  // 单元格大小
  const windowWidth = sheep.$platform.device.windowWidth;
  const cell = computed(() => {
    return (
      (windowWidth -
        (props.styles.marginLeft + props.styles.marginRight + props.styles.padding * 2)) /
      4
    );
  });

  //包裹容器高度
  const parseAdWrap = computed(() => {
    let heightArr = props.data.list.reduce(
      (prev, cur) => (prev.includes(cur.height + cur.top) ? prev : [...prev, cur.height + cur.top]),
      [],
    );
    let heightMax = Math.max(...heightArr);
    return {
      height: heightMax * cell.value + 'px',
      width:
        windowWidth -
        (props.data?.style?.marginLeft +
          props.data?.style?.marginRight +
          props.styles.padding * 2) *
          2 +
        'px',
    };
  });

  // 解析图片大小位置
  const parseImgStyle = (item) => {
    let obj = {
      width: item.width * cell.value -  '7px',
      height: item.height * cell.value - '7px',
      left: item.left * cell.value + 'px',
      top: item.top * cell.value + 'px',
      'border-top-left-radius': props.data.borderRadiusTop + 'px',
      'border-top-right-radius': props.data.borderRadiusTop + 'px',
      'border-bottom-left-radius': props.data.borderRadiusBottom + 'px',
      'border-bottom-right-radius': props.data.borderRadiusBottom + 'px',
    };
  };
  async function getdown(item){
    if(item.type == 'djs'){
      const res = await sheep.$api.goods.qianQuan({
      });
      if(res.code == 1){
        sheep.$helper.toast(res.msg);
      }else{
        sheep.$helper.toast(res.msg);
      }
    }else{
      sheep.$router.go(item.page)
    }
    
  }
</script>

<style lang="scss" scoped>
  .ss-cube-wrap {
    position: relative;
    z-index: 2;
    // width: 750rpx;
    height: 80px;
    padding: 0 15px;
  }

  .cube-img-wrap {
    position: absolute;
    z-index: 3;
    overflow: hidden;
  }

  .cube-img {
    width: 100%;
    height: 100%;
  }
  .dwonclass{
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    height: 100%;
    .downitem{
      width: 48.5%;
      position: relative;
      height: 100%;
      border-radius: 8px;
      .daoview{
        position: relative;
        width: 100%;
        height: 100%;
        .daoviewimg{
          position: absolute;
          width: 100%;
          height: 100%;
          border-radius: 8px;
        }
        .daoitems{
          position: relative;
          width: 100%;
          height: 100%;
          display: flex;
          flex-direction: column;
          align-items: center;
          justify-content: center;
          .jishi{
            
            display: flex;
            flex-direction: row;
            .daonum{
              display: flex;
              color: #fff;
              font-size: 24rpx;
            }
            .jiitem{
              display: flex;
              padding: 2rpx 20rpx;
              color: #fff;
              font-size: 24rpx;
              background-color: red;
              border-radius: 50rpx;
            }
            .qiang{
              display: flex;
              padding: 4rpx 40rpx;
              color: #fff;
              font-size: 26rpx;
              background-color: red;
              border-radius: 50rpx;
            }
          }
          .daomiaotit{
            color: red;
            font-size: 22rpx;
            font-weight: 500;
            display: block;
            margin: 4rpx 0 8rpx;
            height: auto;
          }
        }
      }
    }
    .cube-img{
      position: absolute;
      width: 100%;
      height: 100%;
      border-radius: 8px;
    }
    .downitem:nth-child(even){
      margin-left: auto;
    }
  }
</style>
